package com.z2wenfa.innosticproducer.controller;

import com.z2wenfa.innosticproducer.dao.OrderCountDao;
import com.z2wenfa.innosticproducer.util.JsonWrapperUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

//订货统计控制器
@RestController
@RequestMapping("/ordercount")
public class OrderCountController {
    @Autowired
    private OrderCountDao orderCountDao;

    @RequestMapping("/dataListByCompany")
    public Object getOrderCountDataListByCompany(@RequestParam(value = "companyId", required = false, defaultValue = "0") int companyId,
                                                 @RequestParam(value = "yearId", required = false, defaultValue = "0") int yearId,
                                                 @RequestParam(value = "monthId", required = false, defaultValue = "0") int monthId) {
        return JsonWrapperUtil.wrapperHashMap(orderCountDao.getOrderCountDataListByCompany(companyId, yearId, monthId));
    }

    @RequestMapping("/dataListByMonth")
    public Object getOrderCountDataListByMonth(@RequestParam(value = "companyId", required = false, defaultValue = "0") int companyId,
                                               @RequestParam(value = "yearId", required = true, defaultValue = "0") int yearId,
                                               @RequestParam(value = "monthId", required = false, defaultValue = "0") int monthId) {
        return JsonWrapperUtil.wrapperHashMap(orderCountDao.getOrderCountDataListByMonth(companyId, yearId, monthId));
    }

    @RequestMapping("/dataListByProductType")
    public Object getOrderCountDataListByProductType(@RequestParam(value = "companyId", required = false, defaultValue = "0") int companyId,
                                                     @RequestParam(value = "yearId", required = false, defaultValue = "0") int yearId,
                                                     @RequestParam(value = "monthId", required = false, defaultValue = "0") int monthId) {
        return JsonWrapperUtil.wrapperHashMap(orderCountDao.getOrderCountDataListByProductType(companyId, yearId, monthId));
    }

    @RequestMapping("/dataListByProductTypeFirstLevel")
    public Object getOrderCountDataListByProductTypeFirstLevel(@RequestParam(value = "firstProductLevel") int firstProductLevel, @RequestParam(value = "companyId", required = false, defaultValue = "0") int companyId,
                                                               @RequestParam(value = "yearId", required = false, defaultValue = "0") int yearId,
                                                               @RequestParam(value = "monthId", required = false, defaultValue = "0") int monthId) {
        return JsonWrapperUtil.wrapperHashMap(orderCountDao.getOrderCountDataListByProductTypeFirstLevel(firstProductLevel, companyId, yearId, monthId));
    }

    @RequestMapping("/productTypeList")
    public Object getProductTypeList() {
        return JsonWrapperUtil.wrapperHashMap(orderCountDao.getProductTypeList());
    }


    @RequestMapping("/getTotalOrderValueResultsByYear")
    public Object getTotalOrderValueResultsByYear(@RequestParam(value = "yearId") int yearId) {
        return orderCountDao.getTotalOrderValue(yearId, 0);
    }

    @RequestMapping("/getFirstLevelOrderValueResults")
    public Object getFirstLevelOrderValueResults(@RequestParam(value = "yearId") int yearId) {
        return JsonWrapperUtil.wrapperHashMap(orderCountDao.getFirstLevelEachTypeOrderValue(yearId, 0));
    }

    @RequestMapping("/getSecondLevelOrderValueResults")
    public Object getOrderResultByFirstLevelType(@RequestParam(value = "typePid") int typePid, @RequestParam(value = "yearId") int yearId) {
        return JsonWrapperUtil.wrapperHashMap(orderCountDao.getSecondLevelEachTypeOrderValue(typePid, yearId, 0));
    }


}
